package com.carrent.sxt.servlet;


import com.carrent.sxt.utils.ZXingCodeDecodeUtils;
import com.carrent.sxt.utils.ZXingCodeEncodeUtils;
import reactor.core.publisher.Flux;

import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;

/**
 * @author : 虎虎
 * @date :2020/9/17 13:41
 */
@WebServlet("/decode")
@MultipartConfig
public class DecodeServlet extends HttpServlet {
    private static final long serialVersionId = 1L;
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Part part = req.getPart("mf");
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=utf-8");
        String string = ZXingCodeDecodeUtils.decodeCodeStream(part.getInputStream());
        PrintWriter pw = resp.getWriter();
        pw.write(string);
        pw.flush();
        pw.close();
    }


}